package com.earnings.okhttputils.utils.ui.activity.user;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.earnings.R;
import com.earnings.okhttputils.utils.UrlConstant.Constant;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.ui.activity.common.CodeCheckCommonActivity;
import com.earnings.okhttputils.utils.utils.CommonUtil;

/*
编辑用户信息-忘记支付密码
 */

public class UserEditPaypasswordForgetActivity extends GodLeftHandBaseActivity implements View.OnClickListener {


    View clearName,clearCard;
private Button button;
    private TextView card,name,phone;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_user_edit_realname;
    }

    @Override
    protected void init() {

        setTitle("忘记支付密码");
        findViewById( R.id.info ).setVisibility( View.GONE );
        phone= (TextView) findViewById( R.id.phone );
        card= (TextView) findViewById( R.id.card );
        name= (TextView) findViewById( R.id.name );
        button= (Button) findViewById( R.id.sumbit );
        button.setText( "下一步" );
        button.setBackgroundResource( R.drawable.btn_sumbit_un );
        phone.setText( CommonUtil.getUser().getPhone() );
        clearName=findViewById(R.id.clearName);
        clearCard=findViewById(R.id.clearCard);

        clearName.setOnClickListener(this);
        clearCard.setOnClickListener(this);
        card.addTextChangedListener( new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (card.getText().length() != 0 && name.getText().length() != 0){
                    button.setBackgroundResource( R.drawable.btn_sumbit );
                   button.setOnClickListener( (View.OnClickListener) getContext() );}
                else{

                    button.setBackgroundResource( R.drawable.btn_sumbit_un );
                }
            }
        } );
        name.addTextChangedListener( new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (card.getText().length() != 0 && name.getText().length() != 0){
                    button.setBackgroundResource( R.drawable.btn_sumbit );
                    button.setOnClickListener( (View.OnClickListener) getContext() );}
                else{

                    button.setBackgroundResource( R.drawable.btn_sumbit_un );
                }
            }
        } );
    }


    @Override
    public void onClick(View v) {

        int i = v.getId();
        if (i == R.id.sumbit) {
            bundleData.putString( "phone",phone.getText().toString() );
            bundleData.putString( "name",name.getText().toString() );
            bundleData.putString( "card",card.getText().toString() );
            bundleData.putInt( "type",Constant.SEND_CODE_TYPE_FORGET_PAY_PASSWORD);
            skipActivity( CodeCheckCommonActivity.class );
            finish();
        }  else if (i == R.id.clearName) {
        name.setText( "" );

    } else if (i == R.id.clearCard) {
        card.setText( "" );

    }
    }



}
